#Test script of Org Search
require File.dirname(__FILE__)+'/../lib//testdata/testdata.rb'
require File.dirname(__FILE__)+'/../lib/elements/Sales/element_OrgSearch.rb'
require File.dirname(__FILE__)+'/../lib/reporting.rb'
require File.dirname(__FILE__)+'/../lib/std_lib.rb'
require 'watir'
require 'watir/testcase'


class Org_Search < Watir::TestCase
    # Open a new enviroment of crmint

    # CRM_STD_LIB.judgement_crmint
    # CRM_STD_LIB.login("tony2008","2165270")
=begin
    def test_setup
        #  $ie.bring_to_front
        filename  = File.basename(__FILE__).gsub(/\.rb/, "")
        @@for="tonytest"
        @@search_in="Org Name"

        begin
            $log=Reporting.new(File.dirname(__FILE__)+'/../doc/report/'"",filename)
            if $ie = Watir::IE.find(:title,"ActiveCRM")
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            else
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            end
        rescue
            puts $!
            puts $@
            $log.close unless $log.nil?
        end
    end

    def test_search
        $log.test_notes("Test ActiveCRM")
        $log.test_notes("Start to test Org Search")
        #Data Driven
        #Element::OrgSearch.search_in_select_list.set(@@search_in[])
        #Element::OrgSearch.for_text_field.set(@@for[rand(@@for.size)])
        Element::OrgSearch.search_in_select_list.set(@@search_in)
        Element::OrgSearch.for_text_field.set(@@for)
        Element::OrgSearch.search_button.click
        $log.test_validate($ie.link(:text,"423411").exists?, "Test 423411 exists or not")
        $log.test_validate($ie.link(:text,"523199").exists?, "Test 523199 exists or not")
        sleep 1
        $ie.close 
    
    end
=end
    #Data Driven
    #=begin
    def test_setup
        #Data Driven
        filename  = File.basename(__FILE__).gsub(/\.rb/, "")
        org_search_data = SalesData::OrgSearch.new(File.dirname(__FILE__)+"/../doc/data/testdata.xls")
        begin
            @@testdata = [org_search_data.get_search_in_data,org_search_data.get_for_data,org_search_data.get_market_data]
            $log=Reporting.new(File.dirname(__FILE__)+'/../doc/report/'"",filename)
            if $ie = Watir::IE.find(:title,"ActiveCRM")
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            else
                $ie = Watir::IE.start("https://crmint.dev.activenetwork.com/admin/orgcrm/segmentation/org_market_data_search.cfm")
            end
        rescue
            puts $!
            puts $@
            $log.close unless $log.nil?
        ensure
            org_search_data.close unless org_search_data.nil?
        end
    end

    def test_search
        $log.test_notes("Test ActiveCRM")
        $log.test_notes("Start to test Org Search")
        #Data Driven
        Element::OrgSearch.search_in_select_list.select(@@testdata[0][0])
        Element::OrgSearch.for_text_field.set(@@testdata[1][0].to_i)
        #Element::OrgSearch.search_in_select_list.set(@@search_in)
        #Element::OrgSearch.for_text_field.set(@@for)
        Element::OrgSearch.search_button.click
        $log.test_validate($ie.link(:text,"423411").exists?, "Test 423411 exists or not")
        $log.test_validate($ie.link(:text,"523199").exists?, "Test 523199 exists or not")
        sleep 1
        $ie.close
    end
    #=end

    def test_reset
    
    end
  
    def test_tear_down
        @@for = nil
        @@search_in = nil
    end
end

class NewOrg < Watir::TestCase
    def test_setup
    end
  
    def test_tear_down
        $log.close unless $log.nil?
    end
end


